package dev.caobaoqi6040.backend.infrastructure.security;

import dev.caobaoqi6040.backend.infrastructure.security.jwt.Jwt;
import dev.caobaoqi6040.backend.infrastructure.security.jwt.JwtAuthenticationFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.core.userdetails.UserDetailsService;

/**
 * FilterConfiguration
 *
 * @author caobaoqi6040
 * @since 2025/10/9 15:26
 *
 * @see <a href="https://docs.spring.io/spring-security/reference/servlet/architecture.html#adding-custom-filter">Declaring Your Filter as a Bean</a>
 */
@Configuration
public class FilterConfiguration {

	@Bean
	public FilterRegistrationBean<JwtAuthenticationFilter> jwtAuthenticationFilterFilterRegistrationBean(Jwt jwt, UserDetailsService service) {
		var filter = new FilterRegistrationBean<JwtAuthenticationFilter>();
		filter.setFilter(new JwtAuthenticationFilter(jwt, service));
		filter.setEnabled(false);
		return filter;
	}

}
